{% import "_macros.html" as macros %}
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="/static/lib/html5shiv.js"></script>
<script type="text/javascript" src="/static/lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="/static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="/static/lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="/static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="/static/h-ui.admin/css/style.css" />
<script src="/static/lib/vue/vue.js" type="text/javascript" charset="utf-8"></script>
<script src="https://cdn.staticfile.org/axios/0.18.0/axios.min.js"></script>
<!--[if IE 6]>
<script type="text/javascript" src="/static/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>文章列表</title>
</head>
<body>
<div id="app">
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span>  文章列表 <a class="btn btn-success radius r btn-refresh" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="text-c">
	 <span class="select-box inline">
		<select v-model="typeid" name="typeid" id="typeid" class="select">
			<option value="0">全部分类</option>
			{% for i in category %}
				<option value="{{ i.id }}" {% if typeid==i.id %}selected="selected"{% endif %}>{{ i.catname }}</option>
			{% endfor %}
		</select>
	</span>
	<input type="text" v-model="kw" name="kw" id="kw" placeholder="名称" style="width:250px" class="input-text">
	<button name="" id="ser" class="btn btn-success" type="button"><i class="Hui-iconfont">&#xe665;</i> 搜</button>
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a href="/article" class="btn {% if status==0 %}disabled{% else %}btn-success{% endif %} radius">全部</a> <a href="/article?status=2" class="btn {% if status==2 %}disabled{% else %}btn-success{% endif %} radius" >已发布</a> <a href="/article?status=1" class="btn {% if status==1 %}disabled{% else %}btn-success{% endif %} radius">未发布</a>  <a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> <a class="btn btn-primary radius" data-title="添加资讯" onclick="article_add('添加','/article_add')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 添加资讯</a></span> <span class="r">共有数据：<strong>{{ count }}</strong> 条</span> </div>
	<div class="cl pd-5 bg-1 bk-gray mt-20">
			<button class="btn btn-danger radius" id="torelease">批量发布</button>
			<span class="select-box" style="width: 200px">
				<select v-model="siteid" name="siteid" class="select" id="tosite">
					<option value="0">发布的网站</option>
					{% for i in sitelist %}
					<option value="{{ i.id }}">{{ i.sitename }}/{{ i.url }}</option>
					{% endfor %}
				</select>
			</span>
			<span class="select-box" style="width: 200px">
				<select v-model="sitetypeid" name="sitetypeid" class="select" id="sitetypeid">
					<option value="0">网站分类</option>
				</select>
			</span>
	</div>
	<div class="mt-20">
		<table class="table table-border table-bordered table-bg table-hover table-sort table-responsive">
			<thead>
				<tr class="text-c">
					<th width="25"><input type="checkbox" name="" value=""></th>
					<th>标题</th>
					<th width="80">分类</th>
					<th width="80">来源URL</th>
					<th width="120">更新时间</th>
					<th width="120">添加时间</th>
					<th width="80">状态</th>
					<th width="120">操作</th>
				</tr>
			</thead>
			<tbody>
				 {% for k,i in data %}
				<tr class="text-c">
					<td><input type="checkbox" value="{{ i.id }}" data-title="{{ i.title }}" name="ids[]"></td>
					<td class="text-l"><u style="cursor:pointer" class="text-primary" onClick="article_info('查看','/article_info/{{ i.id }}')" title="查看">{{ i.title }}</u></td>
					<td>{{ i.arttype.catname }}</td>
					<td>{% if i.url %}<a href="{{ i.url }}" target="_blank" title="{{ i.url }}">点击查看</a>{% endif %}</td>
					<td>{{ i.addtime }}</td>
					<td>{{ i.lasttime }}</td>
					<td id="statis{{ i.id }}">{% if i.status==2 %}<span class="c-success">已发布</span>{% else %}<span class="c-warning">未发布</span>{% endif %}</td>
					<td class="f-14 td-manage"><a style="text-decoration:none" onClick="release('发布','/article_release/{{ i.id }}')" href="javascript:;" title="发布"><i class="Hui-iconfont">&#xe603;</i></a> <a style="text-decoration:none" class="ml-5" onClick="article_edit('编辑','/article_edit/{{ i.id }}')" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a> <a style="text-decoration:none" class="ml-5" onClick="article_del(this,{{ i.id }})" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
				</tr>
				{% endfor %}
			</tbody>
		</table>
		{% if pagination %}
		    <div class="pagination">
		    {{ macros.pagination_widget(pagination, '.article',count,field=descset.field,order=descset.order) }}
		    </div>
	    {% endif %}
	</div>
</div>
</div>

<script type="text/javascript">
   var vm = new Vue({
      el: '#app',
      data: {
        typeid: 0,
        siteid: 0 ,
        sitetypeid: 0 ,
        kw:'',
        data:[]
      },
       mounted(){
          axios.get("/article",{
              params:{
                  kw:this.kw,
                  typeid:this.typeid,
                  vue:1
              }
          })
           .then(function (response) {
            this.data = response.data;
          })
           .catch(function (error) {
            console.log(error);
          });
       }
    });
</script>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/static/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/static/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/static/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="/static/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/static/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$("#ser").click(function() {
            kw = $("#kw").val();
            typeid = $("#typeid").val();
            var vhref = document.location.origin+document.location.pathname+"?kw="+kw+"&typeid="+typeid;
            window.location.href = vhref;
        });
});



/*资讯-添加*/
function article_add(title,url,w,h){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}
function article_info(title,url,w,h){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}

/*资讯-编辑*/
function article_edit(title,url,w,h){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}
/*资讯-删除*/
function article_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'GET',
			url: '/article_del?id='+id,
			dataType: 'json',
			success: function(data){
				$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
			},
			error:function(data) {
				console.log(data.msg);
			},
		});
	});
}
/*发布*/
function release(title,url,w,h){
	var index = layer.open({
		type: 2,
		area: ['500px', '300px'],
		title: title,
		content: url
	});
}
/*批量删除*/
function datadel(){
	layer.confirm('确认要删除吗？',function(index){
		var checklist = $("input[name='ids[]']:checked");
		if (checklist.length<=0) {
			layer.msg('请选择要删除的文章!',{icon:5,time:1000});
			return false;
		}
		var postids = []
		for(var i=0; i<checklist.length;i++){
			postids.push(checklist[i].value);
		}
		var indexx = layer.load(1, {shade: [0.1,'#fff']});
		$.post('/article_del',{data:JSON.stringify(postids)},function(data){
			layer.close(indexx);
			layer.msg('已删除!',{icon:1,time:1000});
			setTimeout(function(){
		        window.location.reload();
		    },2000);
		})
	})
}
	$(function(){
		$("#tosite").change(function(e){
			var id = $(this).val();
			$('#sitetypeid').html('<option value="0">网站分类</option>');
			$.get('/to_art_type/'+id,function(data){
				if (data.code==0) {
					layer.msg('error!',{icon:5,time:1000});
					return false;
				}
				$("#sitetype").show();
				var ophtml = '<option value="0">网站分类</option>';
				for (var i = 0; i < data.length; i++) {
					ophtml+='<option value="'+data[i].id+'">'+data[i].name+'</option>';
				}
				$('#sitetypeid').html(ophtml);
			});
		});

		$("#torelease").click(function(){
			var siteid = $("#tosite").val();
			var sitetypeid = $("#sitetypeid").val();
			if (siteid<=0) {
				layer.msg('请选择要发布的网站!',{icon:5,time:1000});
				return false;
			}
			if (sitetypeid<=0) {
				layer.msg('请选择要发布的分类!',{icon:5,time:1000});
				return false;
			}
			var checklist = $("input[name='ids[]']:checked");
			if (checklist.length<=0) {
				layer.msg('请选择要发布的文章!',{icon:5,time:1000});
				return false;
			}
			var indexx = layer.load(1, {shade: [0.1,'#fff']});
			layer.msg('加载中', {
              icon: 16
              ,shade: 0.01
            });
			for(var i=0; i<checklist.length;i++){
				var id = checklist[i].value;
				if(id>0){
					title = $(checklist[i]).attr("data-title");
					$.post('/article_release/'+id,{
						siteid:siteid,
						sitetypeid:sitetypeid
					},function(data){
		                try{
		                    var ojb = JSON.parse(data);
		                }catch(err){
		                    var ojb = data;
		                }
		                if (ojb.code==1) {
		                    layer.msg(title+'发布成功!',{icon:1,time:1000});
		                    document.getElementById("statis"+ojb.data).innerHTML='<span class="c-success">已发布</span>';
		                }else{
		                    layer.msg(ojb.msg,{icon:5,time:1000});
		                }
					})
				}
			}
			layer.close(indexx);
		})
	});
</script>
</body>
</html>